package cloud.xlh.my_system.controller;

import cloud.xlh.domin.po.UserPO;
import cloud.xlh.infrastructure.cache.operate.CacheOperateService;
import cloud.xlh.infrastructure.getter_and_setter.service.Generator4MethodAccessor;
import cloud.xlh.infrastructure.getter_and_setter.service.MethodAccessor;
import com.alibaba.ttl.TransmittableThreadLocal;
import com.yomahub.tlog.core.annotation.TLogAspect;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : xlh_osms
 * @ Author: XuLeHuang
 * @ Date: 2022/10/20 14:59
 * @ Description:
 */
@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {

    @Resource(name = "Caffeine")
    private CacheOperateService caffeineCacheOperateService;

    @Resource(name = "Redis")
    private CacheOperateService redisCacheOperateService;

    /**
    * 注册中心
    * */
    @RequestMapping("/nacosConfigManage")
    public String nacosConfigManage() {
        return "nacosConfigManage";
    }

    private static TransmittableThreadLocal<String> logValueTL = new TransmittableThreadLocal();
    /**
    * 日志
    * */
    @RequestMapping("/tLogTest")
    @TLogAspect(value = {"tLogTest"},pattern = "<-{}->",joint = "_")
    public String tLogTest(String tLogTest) {
        log.info(tLogTest);
        System.out.println(logValueTL.get());
        return tLogTest;
    }

    /**
    * 缓存
    * */
    @RequestMapping("/cacheTest")
    public String cacheTest() {
        caffeineCacheOperateService.put("caffeine" , " caffeine");
        String caffeineValue = (String) caffeineCacheOperateService.getIfPresent("caffeine");
        redisCacheOperateService.put("redis" , "redis");
        String redisValue = (String) redisCacheOperateService.getIfPresent("redis");
        return "caffeineValue : " + caffeineValue ;
    }

    @Resource(name = "Generator4MethodAccessorByJassistImpl")
    private Generator4MethodAccessor generator4MethodAccessor;
    /**
     * getterAndSetter
     * */
    @RequestMapping("/getterAndSetter")
    public String getterAndSetter() {
        MethodAccessor methodAccessor = generator4MethodAccessor.newMethodAccessor(UserPO.class);
        UserPO userPO = new UserPO();
        methodAccessor.set(userPO , "name" , "xlh");
        System.out.println(methodAccessor.get(userPO , "name"));
        return "getterAndSetter内部调用成功" ;
    }
}
